import Vue from "vue"
import VueRouter from "vue-router"
import store from '@/store/index.js'

Vue.use(VueRouter)

const routes = [{
    path: "/",
    redirect: '/login'
},
    {
        path: "/login",
        component: () => import('@/views/login'),
        meta: {
            requireAuth: false,
        }
    },
    {
        path: "/404",
        component: () => import('@/views/404'),
        meta: {
            requireAuth: false,
        }
    },
    {
        path: "/layout",
        component: () => import('@/views/layout'),
        meta: {
            requireAuth: true
        },
        children: [{
            path: "",
            redirect: '/data',
        }, {
            path: "/data",
            component: () => import('@/views/data'),
            meta: {
                requireAuth: true,
                title: "数据概况",
                url: "/data"
            }
        }, {
            path: "/data-setting",
            component: () => import('@/views/data/setting'),
            meta: {
                requireAuth: true,
                title: "数据概况设置",
                url: "/data-setting"
            }
        }, {
            path: "/service-content",
            component: () => import('@/views/service-content'),
            meta: {
                requireAuth: true,
                title: "服务内容",
                url: "/service-content"
            }
        }, {
            path: "/service-content-setting",
            component: () => import('@/views/service-content/setting'),
            meta: {
                requireAuth: true,
                title: "服务内容设置",
                url: "/service-content-setting"
            }
        }, {
            path: "/clues",
            component: () => import('@/views/clues'),
            meta: {
                requireAuth: true,
                title: "商机线索",
                url: "/clues"
            }
        }, {
            path: "/account",
            component: () => import('@/views/account'),
            meta: {
                requireAuth: true,
                title: "账号管理",
                url: "/account"
            }
        }, {
            path: "/permissions",
            component: () => import('@/views/permissions'),
            meta: {
                requireAuth: true,
                title: "权限管理",
                url: "/permissions"
            }
        }, {
            path: "/statistical",
            component: () => import('@/views/statistical'),
            meta: {
                requireAuth: true,
                title: "内容统计",
                url: "/statistical"
            }
        }, {
            path: "/video-record",
            component: () => import('@/views/video-record'),
            meta: {
                requireAuth: true,
                title: "视频创意记录",
                url: "/video-record"
            }
        }, {
            path: "/customer-info",
            component: () => import('@/views/customer-info'),
            meta: {
                requireAuth: true,
                title: "客户信息录入",
                url: "/customer-info"
            }
        }, {
            path: "/customer-info-edit",
            component: () => import('@/views/customer-info/customer-info-edit'),
            meta: {
                requireAuth: true,
                title: "客户信息编辑",
                url: "/customer-info-edit"
            }
        }]
    }
]

const router = new VueRouter({
    mode: 'hash', // hash 或者  history
    routes
})

// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

/** 验证用户是否登录 **/
router.beforeEach((to, from, next) => {
    /*if (to.meta.requireAuth) {
        if (!store.state.token) {
            next({
                path: 'login'
            })
        } else {
            next();
        }
    } else {
        next()
    }*/
    next()
})

export default router;
